<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends CI_Controller
{
	function __construct()
	{
		parent::__construct();

		$this->load->helper('url');
		$this->load->library('tank_auth');
		$this->load->model('posts');
	}
	
	function index()
	{
        $data['page_id'] = "blog";
        $data['posts'] = $this->posts->get_posts(null);
        $post_id  = array_values($data['posts'])[0][0];
        $data['post'] = $this->posts->get_posts($post_id);
        $this->load->view('template/html_head',$data);
        $this->load->view('template/html_script');
        $this->load->view('posts/index', $data);
        $this->load->view('template/html_tail');
	    //$this->view($postId=null);
	}

	function view($postId)
	{
		$data['post'] = $this->posts->get_posts($postId);
		if($postId !== null) 
		{
			$this->load->view('template/html_head',$data);
            $this->load->view('template/html_script');
			$this->load->view('posts/single_view', $data);
			$this->load->view('template/html_tail');
		} else {
			$this->load->view('template/html_head',$data);
            $this->load->view('template/html_script');
			$this->load->view('posts/index', $data);
			$this->load->view('template/html_tail');
		}
	}
}

